<?php
use Application\Model\vn3dUtil;
$cart = $this->cart;
$totalItems=$this->totalItems;
$totalPrice=$this->totalPrice;
?>
<style>
.vn3d-img img{
	width: 40px!important;
	height: auto;
}
.vn3d-desc{
	word-wrap:break-word;
}
.vn3d-item{
	border-bottom: 1px dotted graytext;
	float: left;
}
.btn-close:HOVER {
	color: blue;
	font-size: large;
	font-weight: bold;
}
.vn3d-preview-items{
	width: 350px;
}
</style>
<script>
function reloadPage(){

}
$(document).ready(function(){
	$(".alert").alert();

	$('.btn-close').click(function () {
		var productId=$(this).attr("product");

		console.log("."+productId);
		$.ajax({
	        url: "/store/reomve-item/"+productId,
	        type: "POST",
	        async: false,
	        dataType:"json",
	        success: function(data){
		        if(data.status==1){
		        	$.ajax({
		                url: "/store/preview-cart/",
		                type: "POST",
		                async: true,
		                dataType:"html",
		                success: function(html){
		                $("#vn3d-cart").html(html);

		                },
		                error:function(){
		                    console.log("AJAX request was a failure");
		                }
		              });
	             bootbox.alert("Notice:Product has been deleted successfully.");
	             setTimeout(function(){bootbox.hideAll();},1000);
		        }

	        },
	        error:function(){
	            console.log("AJAX request was a failure");
	        }
	      });

		 reloadPage();
		});
});
</script>
<li class="dropdown" style="height: 30px"><a style="height: 30px"
	href="#" class="dropdown-toggle" data-toggle="dropdown">

	    <span
		class="glyphicon glyphicon-shopping-cart">
		</span>
		<?php if(count($cart)<1){?>
		Cart is empty
		<?php }else{?>
		<span>
		<?php echo $totalItems;?><span> itiem(s) for $<?php echo $totalPrice['sub-total'] ;?></span>
		</span>
		<?php }?>
		 <b
		class="caret"></b>
		</a>
	<ul class="dropdown-menu vn3d-preview-items">
		<?php
            foreach ($cart as $key => $value) {
         ?>
			<li id="<?php echo $value["id"];?>">
			<div class="vn3d-item" style="width: 100%">
             <span class="btn-close pull-right" product="<?php echo $key;?>" title="delete" style="margin: 6px;height: 5px;width: 5px;">×</span>


				<div class="vn3d-img col-md-2">
                 <a
            href="/store/product/<?php echo $value["id"];?>/<?php echo vn3dUtil::convertUrlSeo($value["name"]);?>">
            <img style="-webkit-user-select: none"
        	alt="<?php echo $value["name"];?>" title="<?php echo $value["name"];?>"
        	src="/banner/<?php echo $value["id"];?>/<?php echo $value["id"];?>.png">
        	</a>
               </div>
				<div class="vn3d-desc col-md-9">
					<a href="/store/product/<?php echo $value["id"];?>/<?php echo vn3dUtil::convertUrlSeo($value["name"]);?>"><?php echo $value["name"];?></a>
				    <br><span >$<?php echo $value["price"];?></span>
				</div>



    </div>
		</li>
			<?php
             }
          ?>

			<li>
			<?php if(count($cart)>0){?>
			<div style="width: 100%; float: left;padding-left: 10px">
			<hr>
               <a href="/store/cart" class="btn btn-sm btn-default"
			role="button">VIEW CART</a>
			</div>
            <?php }else{?>
           <center><span>Cart is empty</span></center>
            <?php }?>
			</li>

	</ul></li>
